﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ECGWeb.Controls
{
    public partial class DataTable : System.Web.UI.UserControl
    {
        public ECGService.HistoryRecord[] historyRecordArray = null;        

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.record_gridview.PageIndexChanging += gridview_PageIndexChanging;
        }        

        protected void gridview_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            record_gridview.PageIndex = e.NewPageIndex;
            record_gridview.DataBind();          
            recordUpdatePanel.Update();
        }

        public void setDataSource(ECGService.HistoryRecord[] hr)
        {
            this.historyRecordArray = hr;
            record_gridview.DataSource = hr;
            record_gridview.DataBind();
        }

        public void fakeRecordGridViewData()
        {
            ECGService.HistoryRecord[] historyRecordArrayFake = new ECGService.HistoryRecord[1];
            historyRecordArrayFake[0] = new ECGService.HistoryRecord();
            historyRecordArrayFake[0].recordID = "fake";
            historyRecordArrayFake[0].dateTimeOfRecord = DateTime.Now;

            record_gridview.DataSource = historyRecordArrayFake;
            record_gridview.DataBind();
            record_gridview.Rows[0].Visible = false;
            record_gridview.Rows[0].Controls.Clear();
        }

        public UpdatePanelUpdateMode UpdateMode
        {
            get { return this.recordUpdatePanel.UpdateMode; }
            set { this.recordUpdatePanel.UpdateMode = value; }
        }

        public void Update()
        {
            recordUpdatePanel.Update();
        }
    }
}